<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
    <el-col :span="6">
        <el-form-item :label="$t('running.id')">
          <el-input v-model="dataForm.id" :placeholder="$t('running.id')" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item :label="$t('running.definitionKey')">
          <el-input v-model="dataForm.definitionKey" :placeholder="$t('running.definitionKey')" clearable></el-input>
        </el-form-item>
      </el-col>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table :loading="dataListLoading" :data="dataList" ref="xTable" auto-resize class="vxe-table-element"
          remote-sort @sort-change="dataListSortChangeHandle" max-height="auto">
          <vxe-table-column type="index" width="50" align="center"></vxe-table-column>
          <vxe-table-column field="processInstanceId" title="running.id"></vxe-table-column>
          <vxe-table-column field="processDefinitionKey" title="running.definitionKey"></vxe-table-column>
          <vxe-table-column field="processDefinitionName" title="running.processDefinitionName"></vxe-table-column>
          <vxe-table-column field="originator" title="发起人" width="100" align="center"></vxe-table-column>
          <vxe-table-column field="currTaskName" title="running.activityId"></vxe-table-column>
          <vxe-table-column field="suspended" title="running.suspended" width="80" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.suspended" size="small">{{ $t('running.suspended1') }}</el-tag>
              <el-tag v-else size="small" type="danger">{{ $t('running.suspended0') }}</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column field="startTime" title="启动时间" width="140" align="center"></vxe-table-column>
          <vxe-table-column title="handle" width="160" align="center">
            <template slot-scope="scope">
              <el-button v-if="scope.row.procBizId" type="text" size="small"
                @click="viewHistoricDetailHandle(scope.row.procBizId,scope.row.processInstanceId,scope.row.formId,scope.row.bizId)"
                icon="el-icon-printer">审批记录
              </el-button>
              <el-button type="text" icon="el-icon-delete" size="small"
                @click="deleteHandle(scope.row.processInstanceId)">{{ $t('delete') }}
              </el-button>
            </template>
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
          layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/act/running/page',
        getDataListIsPage: true,
        deleteURL: '/act/running'
      },
      dataForm: {
        id: '',
        definitionKey: '',
        startUser: ''
      }
    }
  },
  methods: {
    viewHistoricDetailHandle (procBizId, procInstId, formId, bizId) {
      this.$nextTick(() => {
        var router = {
          name: 'process-history',
          id: procInstId,
          menuId: this.$route.meta.menuId,
          oldName: 'flowable-bpmProcBiz',
          path: 'flowable/process-history',
          title: '流程进度详情'
        }

        var params = {
          procBizId: procBizId,
          procInstId: procInstId,
          formId: formId,
          bizId: bizId

        }
        this.$options.methods.openNewTab(this.$router, router, params)
      })
    }
  }
}
</script>
